var searchData = {};

$( function () {
$( ".check-btn" ).on( "click" , function () {
$( this ).parent( "li" ).find( "div" ).each( function () {
$( this ).css( "display" , "block" );
} )
$( this ).parent( "li" ).siblings( "li" ).each( function () {
$( this ).find( "div" ).each( function () {
$( this ).css( "display" , "none" );
} )
} )
} )
$( ".yesBtn" ).on( "click" , function () {
$( this ).parent( "div" ).css( "display" , "none" );
$( this ).parent( "div" ).prev().css( "display" , "none" );
} )

$( ".select_a" ).on( "click" , function () {
var divId = $( this ).attr( "click_div" );
$( ".select_a_div_triangle" ).css( "display" , "none" );
$( ".select_a_div" ).css( "display" , "none" );
$( "#" + divId ).css( "display" , "block" );
$( "#" + divId ).prev().css( "display" , "block" );
} )

$( ".reduce_give" ).click( function () {
$( ".reduce_give" ).removeClass( "active_a" );
$( this ).addClass( "active_a" );
var value = $( this ).attr( "data_value" );
if(value == "减"){
$(".hid").show();
}else{
$(".hid").hide();
}
$( "#zhongjian" ).html( value );
} );

$( '#supply_table' ).bootstrapTableEx( {
height : 400 ,
url : '/apishop/Product/getProducApi' ,
columns : [
{
checkbox : true
} , {
field : 'id' ,
align : 'center' ,
title : '商品ID'
} , {
field : 'name' ,
align : 'center' ,
title : '商品名称'
} , {
field : 'price' ,
align : 'center' ,
title : '价格'
} , {
field : 'stock' ,
align : 'center' ,
title : '库存'
} , {
field : 'sale_num' ,
align : 'center' ,
title : '实际销量'
} ,
{
field : 'category_id' ,
align : 'center' ,
title : '分类'
} , {
field : 'brand_id' ,
align : 'center' ,
title : '品牌'
} , {
field : 'is_shelves' ,
title : '操作' ,
align : 'center' ,
formatter : isShelves
}
] ,
queryParams : function ( params ) {
var param = {
search : searchData ,
pageSize : params.pageSize ,
pageNumber : params.pageNumber
};
return param;
} ,
responseHandler : function ( res ) {
if ( res.data ) {
return {
rows : res.data ,
total : res.count
};
}
}
} );
// $( '#stock_table' ).bootstrapTableEx( {
//     // url : '../../sys/user/list?_' + $.now(),
//     height : $( window ).height() - 54 ,
//     queryParams : function ( params ) {
//         params.searchText
//         return params;
//     } ,
//     columns : [
//         {
//             checkbox : true
//         } , {
//             field : 'id' ,
//             title : '商品ID</br>ssads'
//         } , {
//             field : 'name' ,
//             title : '商品名称'
//         } , {
//             field : 'price' ,
//             title : '价格'
//         } , {
//             field : 'num' ,
//             title : '库存'
//         } , {
//             field : 'number' ,
//             title : '实际销量'
//         } , {
//             field : 'type' ,
//             title : '分类'
//         } , {
//             field : 'pingpai' ,
//             title : '品牌'
//         } , {
//             field : 'is_shelves' ,
//             title : '商品状态'
//         }
//     ] ,
//     data : [
//         {
//             "id" : 1 ,
//             "name" : "牛肉" ,
//             "price" : 1.00 ,
//             "num" : 11 ,
//             "number" : 12 ,
//             "type" : "肉类" ,
//             "pingpai" : "杂牌"
//         }
//     ]
// } );
$( '#discount_table' ).bootstrapTableEx( {
height : 350 ,
url : '/supplies/Shopweb/getDiscountList' ,
columns : [
{
checkbox : true
} , {
field : 'id' ,
align : 'center' ,
title : '商品ID' ,
} , {
field : 'name' ,
align : 'center' ,
title : '活动名称'
} , {
field : 'type' ,
title : '活动类型' ,
align : 'center' ,
formatter : discountTyep
} , {
field : 'start_time' ,
title : '开始时间' ,
align : 'center' ,
} , {
field : 'end_time' ,
title : '结束时间' ,
align : 'center' ,
} ,
{
field : 'add_time' ,
title : '添加时间' ,
align : 'center' ,
}
] ,
queryParams : function ( params ) {
var param = {
search : searchData ,
pageSize : params.pageSize ,
pageNumber : params.pageNumber
};
return param;
} ,
responseHandler : function ( res ) {
if ( res.data ) {
return {
rows : res.data ,
total : res.count
};
}
}
} );
} )

function isShelves( val , row , index ) {
var res;
if ( row.is_shelves == 1 ) {
res = "<a href='javascript:void(0);' class='status_a form-group'>下架<br/>Shelves</a>"
// res = '上架中';
} else if ( row.is_shelves == 2 ) {
res = "<a href='javascript:void(0);' class='status_a form-group'>上架<br/>UT shelf</a>"
// res = '已下架';
} else if ( row.is_shelves == 3 ) {
// res = "<a href='javascript:void(0);' class='status_a'>下架</a>"
res = "<a href='javascript:void(0);' class='status_a form-group'>审核中<br/>UT shelf</a>"
// res = '审核中';
}
var divStr = "<div class='form-inline'>"
    var deleteStr = "<a href='javascript:void(0);' class='delete_a  form-group'></a>"
    divStr += res;
    divStr += deleteStr;
    divStr += "</div>";
// res = res + deleteStr;
return divStr;
}

function discountTyep( val , row , index ) {
var res;
if ( row.type == 1 ) {
res = '满减';
} else if ( row.type == 2 ) {
res = '满送';
} else {
res = '暂无分类';
}
return res;
}

vm = new Vue( {
el : "#myTabContent" ,
data : {
category : {
category : [] ,
type : [] ,
small_type : [] ,
brand : [] ,
} ,
searchData : {
name : '' ,
category : {
category_ids : [] ,
type_ids : [] ,
small_type_ids : [] ,
brand_ids : [] ,
} ,
price : {
up : '' ,
down : '' ,
} ,
stock : {
up : '' ,
down : '' ,
} ,
is_shelves : '0' ,
discount_type : '' ,
discount_status : '' ,
discount_name : '' ,
} ,
saveData : {
name : '' ,
discription : '' ,
origin : '' ,
img : '' ,
imgs : '' ,
price : '' ,
stock : '' ,
tax : '' ,
is_shelves : '' ,
} ,
} ,
methods : {
searchs : function ( index ) {
searchData = this.searchData;
if ( index == 1 ) {
$( "#supply_table" ).bootstrapTable( 'refresh' );
} else {
$( "#discount_table" ).bootstrapTable( 'refresh' );
}
} ,
getType : function ( first , second ) {
var _this = this , data = { parent_id : this.searchData.category[ first ] };
axios.post( '/supplies/Shopweb/getThreeType' , data , {
emulateJSON : true
} ).then( function ( res ) {
_this.category[ second ] = res.data;
} , function ( res ) {
layer.msg( '网络错误！' );
} );
} ,
getShelves : function ( index ) {
this.searchData.is_shelves = index;
} ,
getDiscountType : function ( index ) {
this.searchData.discount_type = index;
} ,
getDiscountStatus : function ( index ) {
this.searchData.discount_status = index;
} ,
setShelves : function ( index ) {
var url , allData = $( '#supply_table' ).bootstrapTable( 'getAllSelections' ) , arr = [];
if ( allData == 0 ) {
layer.msg( '请选择需要修改的数据！' );
return false;
}
for ( var i = 0 ; i < allData.length ; i++ ) {
if ( allData[ i ][ 'is_shelves' ] > 2 ) {
layer.msg( '审核中商品无法上架，请重新选择！' );
return false;
}
arr.push( allData[ i ][ 'id' ] );
}
var data = { id : arr };
if ( index == 1 ) {
url = '/apishop/Product/upProduct';
} else if ( index == 2 ) {
url = '/apishop/Product/downProduct';
} else if ( index == 4 ) {
url = '/apishop/Product/delProduct';
}
axios.post( url , data , {
emulateJSON : true
} ).then( function ( res ) {
if ( res.data.status == 200 ) {
layer.msg( res.data.msg );
$( "#supply_table" ).bootstrapTable( 'refresh' );
} else {
layer.msg( res.data.msg );
}
} , function () {
layer.msg( '网络错误！' );
} );
} ,
} ,
mounted : function () {
this.getType( null , 'category' );
} ,

} );

